/*! rws.nl v1.0.0, 27-10-14 */
(function() {
  this.App = {
    $doc: $(document),
    $win: $(window),
    doc: {},
    win: {},
    scrollY: 0,
    scrollX: 0
  };

  Hammer.NO_MOUSEEVENTS = true;

  this.uniqueId = (function() {
    var x;
    x = 0;
    return function() {
      return x++;
    };
  })();

  (function() {
    var collectSizes, last_ev, requestTick, scrollNode, ticking, triggerEvent;
    ticking = false;
    last_ev = "ready";
    scrollNode = document.documentElement || document.body.parentNode || document.body;
    collectSizes = function(evType) {
      if ((evType != null) !== 'scroll') {
        App.doc.width = App.$doc.width();
        App.doc.height = App.$doc.height();
        App.win.width = App.$win.width();
        App.win.height = App.$win.height();
      }
      App.scrollY = (function() {
        if (window.pageYOffset != null) {
          return window.pageYOffset;
        } else {
          return scrollNode.scrollTop;
        }
      })();
      return App.scrollX = (function() {
        if (window.pageXOffset != null) {
          return window.pageXOffset;
        } else {
          return scrollNode.scrollLeft;
        }
      })();
    };
    triggerEvent = function() {
      if (last_ev) {
        collectSizes(last_ev);
        App.$win.trigger("screenchange");
        switch (last_ev) {
          case 'scroll':
            App.$win.trigger("scrollend");
            break;
          case 'resize' || 'orientationchange':
            App.$win.trigger("resizeend");
        }
      }
      ticking = false;
      return last_ev = null;
    };
    requestTick = function() {
      if (!ticking) {
        requestAnimationFrame(triggerEvent);
        return ticking = true;
      }
    };
    requestTick();
    App.$win.on("load resize orientationchange scroll", function(ev) {
      last_ev = ev.type;
      requestTick();
      return collectSizes();
    });
    return collectSizes();
  })();

  $.extend($.easing, {
    easeInQuad: function(x, t, b, c, d) {
      return c * (t /= d) * t + b;
    },
    easeOutQuad: function(x, t, b, c, d) {
      return -c * (t /= d) * (t - 2) + b;
    }
  });

}).call(this);

/**
 * modified for RWS.nl
 */
var YASS = (function(win, doc) {

  var docEl = doc.documentElement,
    screen = win.screen,

    // collect all instances
    instances = [],

    // media query input data
    media = {},

    // default options
    options = merge({
        yass_attr: 'data-yass',
        src_attr: 'src',
        srcset_attr: 'data-srcset',
        resize_timeout: 50
      }, win.YASS_OPTIONS || {});


  /**
   * SrcSet object per obj in the document
   * @param obj
   * @param [inst_options]
   * @param [callback]
   * @constructor
   */
  function SrcSet(obj, inst_options, callback) {
    if(inst_options) {
      this.options = merge(options, inst_options);
    } else {
      this.options = options;
    }

    this.callback = callback || function(){};
    this.obj = obj;

    this.candidates = null;
    this.has_srcset = obj.getAttribute(this.options.srcset_attr);

    obj.setAttribute(this.options.yass_attr, true);

    this.collectCandidates();
    this.update();
  }


  SrcSet.prototype = {

    /**
     * parse the srcset attribute as an array
     */
    collectCandidates: function() {
      // already got the candidates
      if(this.candidates || !this.has_srcset) {
        return;
      }

      this.candidates = [];

      // read the srcset attribute
      var attr = this.obj.getAttribute(this.options.srcset_attr),
        parts = attr.split(/\s*,\s*/g);

      // walk the srcsets and collect the properties
      for(var i = 0; i < parts.length; i++) {
        var props = parts[i].split(" "),
          values = {
            src: props.shift(),
            w: 0,
            h: 0,
            x: 1
          };

        for(var p = 0; p < props.length; p++) {
          values[props[p].slice(-1)] = parseFloat(props[p]);
        }

        this.candidates.push(values);
      }

      // also append the initial obj to the set
      if(this.obj.src) {
        this.candidates.push({
          src: this.obj[this.options.src_attr],
          w: 0,
          h: 0,
          x: 1
        });
      }


      // sort srcsets from high to low
      this.candidates.sort(function(a,b) {
        if(a.x > b.x) { return -1; }
        if(a.x < b.x) { return 1; }

        if(a.w > b.w) { return -1; }
        if(a.w < b.w) { return 1; }

        if(a.h > b.h) { return -1; }
        if(a.h < b.h) { return 1; }

        return 1;
      });
    },


    /**
     * get the src matching current viewport
     */
    getSrc: function() {
      var c, i;
      for(i = 0; i < this.candidates.length; i++) {
        c = this.candidates[i];

        if(c.x <= media.density &&
          (c.w === 0 || c.w < media.width) &&
          (c.h === 0 || c.h < media.height)) {
          return c.src;
        }
      }

      // return the smallest, probarly the initial
      return c.src;
    },


    /**
     * update the obj
     */
    update: function() {
      var obj = this.obj;
      // only if the obj still exists
      if(obj.parentNode && this.has_srcset) {
        var new_src = this.getSrc();

        if(obj.getAttribute(this.options.src_attr) != new_src) {
          obj.setAttribute(this.options.src_attr, new_src);
          this.callback.call(this, new_src);

          $(obj).trigger("yassupdate");
        }
      }
    }
  };


  /**
   * simple merge objects into a new one
   * @param   {object}  obj1
   * @param   {object}  obj2
   * @returns {object}  merged
   */
  function merge(obj1, obj2) {
    var merged = {};
    for(var key in obj1) {
      merged[key] = obj2[key] || obj1[key];
    }
    return merged;
  }


  /**
   * look at the document for new images and register these
   */
  function registerImages() {
    // create instances
    var imgs = doc.images;
    for(var i = 0, len = imgs.length; i < len; i++) {
      if(imgs[i].getAttribute(options.srcset_attr) && !imgs[i].getAttribute(options.yass_attr)) {
        instances.push(new SrcSet(imgs[i]));
      }
    }
  }


  /**
   * get media properties to test the srcSet values
   */
  function getMediaProperties() {
    media = {
      width: win.innerWidth || docEl.clientWidth || screen.width,
      height: win.innerHeight || docEl.clientHeight || screen.height,
      density: win.devicePixelRatio || 1
    };
  }


  /**
   * update all images to match their srcset
   */
  function update() {
    getMediaProperties();
    for(var i = 0, len = instances.length; i < len; i++) {
      instances[i].update();
    }
  }


  /**
   * try to trigger update in an animation frame
   */
  function triggerUpdate() {
    (win.requestAnimationFrame) ? win.requestAnimationFrame(update) : update();
  }


  // initial magic
  getMediaProperties();
  registerImages();


  // update on resize
  App.$win.on("resizeend", update);


  /**
   * you can also create new instances, so you can create things like responsive iframes
   * by default it returns an update and register method
   *
   * @param [obj=null]
   * @param [options=null]
   * @param [callback=null]
   */
  return function(obj, options, callback) {
    if(obj) {
      var inst = new SrcSet(obj, options, callback);
      instances.push(inst);
      return inst;
    }

    registerImages();
    triggerUpdate();
    return instances;
  };
})(window, document);
(function() {
  var htmlbody, id_selector, scrollToAnchor, _ref,
    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

  id_selector = /^#[a-zA-Z0-9\-_]+$/;

  htmlbody = ((_ref = (__indexOf.call($("html")[0], "scrollTop") >= 0)) != null ? _ref : $("html")) || $("body");

  scrollToAnchor = function(hash, ev) {
    var target, top, _ref1;
    if (hash.match(id_selector)) {
      target = $(hash);
      if (target.length) {
        ev.preventDefault();
        top = (_ref1 = target.offset()) != null ? _ref1.top : void 0;
        return htmlbody.animate({
          scrollTop: top
        }, 200, function() {
          return window.location.hash = hash;
        });
      }
    }
  };

  $(document.body).on("click", "a[href^='#']:not(.noscroll)", function(ev) {
    return scrollToAnchor($(this).attr("href"), ev);
  });

}).call(this);

(function() {
  App.Carousel = function(el) {
    var cur_index, goToSlideLink, hammertime, interval, overview, pauseToggle, paused, play, playSooner, showNext, showPrev, showSlide, slides, stop, timer;
    slides = el.find(".carousel-slide");
    overview = el.find(".carousel-overview li");
    timer = null;
    paused = window.CAROUSEL_PAUSED || false;
    interval = 6000;
    cur_index = 0;
    hammertime = new Hammer(el[0], {
      drag_block_horizontal: true
    });
    hammertime.on("swipeleft swiperight", function(ev) {
      if (ev.type === 'swiperight') {
        return showPrev();
      } else {
        return showNext();
      }
    });
    play = function() {
      if (paused) {
        return;
      }
      stop();
      return timer = setTimeout(showNext, interval);
    };
    playSooner = function() {
      if (paused) {
        return;
      }
      stop();
      return timer = setTimeout(showNext, interval / 3);
    };
    stop = function() {
      clearTimeout(timer);
      return timer = null;
    };
    pauseToggle = function() {
      if (timer) {
        paused = true;
        stop();
      } else {
        paused = false;
        playSooner();
      }
      return paused;
    };
    showNext = function() {
      var next_index;
      cur_index = slides.filter(".active").index();
      if (slides[cur_index + 1]) {
        next_index = cur_index + 1;
      } else {
        next_index = 0;
      }
      return showSlide(next_index);
    };
    showPrev = function() {
      var next_index;
      cur_index = slides.filter(".active").index();
      if (slides[cur_index - 1]) {
        next_index = cur_index - 1;
      } else {
        next_index = slides.length - 1;
      }
      return showSlide(next_index);
    };
    showSlide = function(index) {
      var current, next, prev;
      stop();
      slides.removeClass("active").removeClass("next").removeClass("prev");
      overview.removeClass("active");
      current = $(slides.get(index));
      current.addClass("active");
      next = current.next();
      if (!next.length) {
        next = slides.first();
      }
      next.addClass("next");
      prev = current.prev();
      if (!prev.length) {
        prev = slides.last();
      }
      prev.addClass("prev");
      cur_index = index;
      $(overview.get(index)).addClass("active");
      return play();
    };
    goToSlideLink = function(index) {
      var href;
      href = $(slides.get(index)).find("a:first").attr("href");
      if (href) {
        return location.href = href;
      }
    };
    overview.on("mouseover focus click", "a", function(ev) {
      var index, li;
      li = $(this).closest("li");
      index = li.index();
      if (ev.type === 'click' && cur_index === index) {
        goToSlideLink(index);
      }
      showSlide(index);
      return false;
    });
    slides.on("mouseenter mouseleave", function(ev) {
      if (ev.type === 'mouseenter') {
        return stop();
      } else {
        return playSooner();
      }
    });
    el.find("a.toggle-pause").on("click", function(ev) {
      var state;
      state = pauseToggle();
      $("span", this).text(state ? 'Hervatten' : 'Onderbreken');
      $(this).toggleClass("paused", state);
      return ev.preventDefault();
    });
    play();
    return showSlide(0);
  };

  $(".carousel").each(function() {
    return App.Carousel($(this));
  });

}).call(this);

(function() {
  App.Cover = (function() {
    var api, container, slideshow, toggle_el;
    container = $(".site-cover");
    slideshow = {};
    toggle_el = null;
    return api = {
      el: container,
      updateMaxHeight: function() {
        if (container.hasClass("expand")) {
          return container.css("max-height", App.win.height - container.offset().top - 20);
        } else {
          return container.css("max-height", "none");
        }
      },
      findSlides: function() {
        var el, images;
        el = container.find(".cover-slideshow");
        images = el.attr("data-images");
        if (images) {
          slideshow = new App.SlideShow(el);
          slideshow.addSlides(images.split(/\s*;\s*/g));
          container.addClass("has-slideshow");
          return slideshow.build();
        }
      },
      appendToggle: function() {
        toggle_el = $("<a href='#' class='toggle'>Bekijk beeldmateriaal</a>").appendTo(container);
        return toggle_el.on("click", function(ev) {
          api.toggle();
          return ev.preventDefault();
        });
      },
      getSlideshow: function() {
        return slideshow;
      },
      toggle: function(toggle) {
        var label;
        container.toggleClass("expand", toggle);
        if (toggle_el) {
          label = "Bekijk beeldmateriaal";
          if (container.hasClass("expand")) {
            label = "Sluit beeldmateriaal";
            slideshow.show(0);
          }
          toggle_el.text(label);
        }
        return api.updateMaxHeight();
      }
    };
  })();

  $(function() {
    if (App.Cover.findSlides()) {
      App.Cover.appendToggle();
    }
    return App.$win.on("resizeend", App.Cover.updateMaxHeight);
  });

}).call(this);


/*
  .expandable
    a.expandable-toggle(href="#") Openen
    .expandable-body
      h2 hi!

  OR

  a.expandable-toggle(href="#target") Openen
   *target.expandable-hide
    h2 hi!
 */

(function() {
  var findTarget, toggleStateForTargetToggles;

  findTarget = function($toggle) {
    var $hrefTarget;
    $hrefTarget = $($toggle.attr("href"));
    if ($hrefTarget != null ? $hrefTarget.length : void 0) {
      return $hrefTarget;
    }
    return $toggle.closest(".expandable").find(".expandable-body");
  };

  toggleStateForTargetToggles = function($target, state) {
    return $(".expandable-toggle").each(function() {
      var $toggle, text, _ref;
      $toggle = $(this);
      if ((_ref = $toggle.data("expand-target")) != null ? _ref.is($target) : void 0) {
        $toggle.toggleClass("collapse", state);
        if (state) {
          text = $toggle.data("collapse-text");
        } else {
          text = $toggle.data("expand-text");
        }
        if (text) {
          return $toggle.text(text);
        }
      }
    });
  };

  $("body").on("click", ".expandable-toggle", function(ev) {
    var $container, $target, $toggle;
    ev.preventDefault();
    ev.stopPropagation();
    $toggle = $(this);
    $toggle.data("expand-text", $toggle.data("expand-text") || false);
    $toggle.data("collapse-text", $toggle.data("collapse-text") || false);
    $toggle.data("expand-target", findTarget($toggle));
    $target = $toggle.data("expand-target");
    $container = $target.closest(".expandable");
    return $target.slideToggle(200, function() {
      if ($container.length) {
        $container.toggleClass("expand");
      }
      $toggle.toggleClass("collapse");
      if ($toggle.hasClass("collapse")) {
        return toggleStateForTargetToggles($target, true);
      } else {
        return toggleStateForTargetToggles($target, false);
      }
    });
  });

}).call(this);

(function() {
  var round;

  round = function(val, decimals) {
    var delta;
    if (decimals == null) {
      decimals = 0;
    }
    delta = Math.pow(10, decimals);
    return Math.round(val * delta) / delta;
  };

  $("a.find-location").on('click', function(ev) {
    var el, input, setLatLng;
    el = $(this);
    input = $(el.attr('href'));
    setLatLng = function(lat, lng) {
      return input.val("(" + (round(lat, 3)) + ", " + (round(lng, 3)) + ")");
    };
    if (input) {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(pos) {
          if (pos != null ? pos.coords : void 0) {
            return setLatLng(pos.coords.latitude, pos.coords.longitude);
          }
        });
      } else {
        $.getJSON("//www.telize.com/geoip?callback=?", function(data) {
          if (data) {
            return setLatLng(data.latitude, data.longitude);
          }
        }).fail(function() {
          return $.getJSON("//freegeoip.net/json?callback=?", function(data) {
            if (data) {
              return setLatLng(data.latitude, data.longitude);
            }
          });
        });
      }
      return false;
    }
  });

}).call(this);

(function() {
  var carousel, img;

  img = $("img.knmi-weeralarm");

  if (img.length) {
    img.on("load", function() {
      if (img.height() > 10) {
        return img.addClass("show");
      }
    });
    setTimeout((function() {
      if (!img.hasClass("show")) {
        return img.attr("src", "about:blank").remove();
      }
    }), 2000);
  }

  if (Modernizr.backgroundsize) {
    carousel = $('.landing-carousel .carousel-slides');
    if (carousel.length) {
      App.$win.on("ready load resizeend", function(ev) {
        return carousel.css("max-height", App.win.height - carousel.offset().top - 120);
      });
    }
  }

}).call(this);

(function() {
  (function() {
    return $("iframe[data-srcset]").each(function() {
      return YASS(this).update();
    });
  })();

}).call(this);

(function() {
  var selector, setAsBgImage, showErrorImage;

  if (!Modernizr.backgroundsize) {
    return;
  }

  setAsBgImage = function(img) {
    var new_bg, style;
    new_bg = "url(" + img.src + ")";
    style = img.parentNode.style;
    if (style.backgroundImage !== new_bg) {
      return style.backgroundImage = new_bg;
    }
  };

  showErrorImage = function(img) {
    return $(img).addClass("bgimage-error");
  };

  selector = ["img.background", ".jumbo-img img", ".wall-item img", ".landing-cover img", ".cover-item img"].join(", ");

  $(selector).each(function() {
    return setAsBgImage(this);
  }).on("load", function() {
    return setAsBgImage(this);
  }).on("error", function() {
    return showErrorImage(this);
  });

}).call(this);

(function() {
  (function() {
    return $(document.body).on("focus blur", "a", function(ev) {
      var anchor, dropdown;
      anchor = $(this);
      dropdown = anchor.closest(".mega-dropdown");
      if (dropdown.length) {
        return dropdown.addClass("open");
      } else {
        return $(".mega-dropdown.open").removeClass("open");
      }
    });
  })();

  (function() {
    var prev_el;
    if (Hammer.HAS_TOUCHEVENTS) {
      prev_el = {};
      return $("#nav").on("click", ".main-item > a", function(ev) {
        if (App.win.width >= 900) {
          if (prev_el !== this) {
            prev_el.click_counter = -1;
          }
          prev_el = this;
          if (this.click_counter == null) {
            this.click_counter = 0;
          } else {
            this.click_counter++;
          }
          return !!(this.click_counter % 2);
        }
      });
    }
  })();

}).call(this);

(function() {
  var has_pagenav;

  App.MobileNav = (function() {
    var clickInpageLink, clickMainLink, clickToggleLink, fx_speed, inpagenav, is_enabled_main_link, is_enabled_toggle_link, is_ready, mainnav, navcontainer;
    is_ready = false;
    is_enabled_toggle_link = false;
    is_enabled_main_link = false;
    fx_speed = 250;
    navcontainer = $(".site-nav");
    inpagenav = $("#nav-inpage");
    mainnav = $("#nav");

    /*
    toggle links
     */
    clickInpageLink = function(ev) {
      return inpagenav.hide();
    };

    /*
    toggle links
     */
    clickToggleLink = function(ev) {
      var href, target;
      href = this.getAttribute('href');
      target = $(href);
      $("#nav-slide, #nav-search, #nav-inpage").not(target).hide();
      if (href === '#nav') {
        $("html").toggleClass("show-nav");
      } else {
        target.slideToggle(fx_speed);
      }
      return false;
    };

    /*
    toggle mega dropdowns
     */
    clickMainLink = function(ev) {
      var li, megadd;
      console.log(ev, is_enabled_main_link);
      if (is_enabled_main_link) {
        //alert('jo');
        li = $(this).closest("li.main-item");
        megadd = li.find(".mega-dropdown");
        mainnav.find("li.main-item.open").not(li).removeClass("open");
        if (megadd.length) {
          megadd.slideToggle(fx_speed, function() {
            li.toggleClass("open");
            return megadd.removeAttr("style");
          });
          return ev.preventDefault();
        }
      }
    };

    /*
    setup navigation
     */
    return {
      enableMainLink: function(toggle) {
        return is_enabled_main_link = toggle;
      },
      enableToggleLink: function(toggle) {
        return is_enabled_toggle_link = toggle;
      },
      init: function(enable) {
        if (is_ready) {
          return;
        }
        is_ready = true;
        mainnav.find("li.main-item.active").addClass("open");
        navcontainer.on("click", ".toggles a", clickToggleLink);
        mainnav.on("click", "li.main-item > a", clickMainLink);
        inpagenav.on("click", "a", clickInpageLink);
        if (has_pagenav) {
          $("a.toggle-inpage").show();
          return inpagenav.append($(".site-pagenav nav").clone());
        }
      }
    };
  })();

  has_pagenav = $(".site-pagenav nav ul li").length;

  App.$win.on("ready resizeend", function() {
    if (!has_pagenav) {
      $("a.toggle-inpage").remove();
    }
    if (App.win.width <= 1200) {
      App.MobileNav.init(true);
      App.MobileNav.enableMainLink(App.win.width < 900);
      return $("a.toggle-inpage").show();
    } else {
      return App.MobileNav.init(false);
    }
  });

}).call(this);

(function() {
  $("a[target='overlay']").on("click", function(ev) {
    window.open(this.href, 'overlay', 'width=800,height=600,scrollbars=yes,resizable=yes,toolbar=no,location=no');
    return ev.preventDefault();
  });

}).call(this);

(function() {
  var anchors, cur_index, el, prev_index, spy_elements, toggle;

  el = $(".site-pagenav");

  toggle = el.find("a.toggle");

  toggle.bind('click', function(ev) {
    el.toggleClass("expand");
    return ev.preventDefault();
  });

  el.find("li a").bind('click', function() {
    return el.removeClass("expand");
  });

  spy_elements = [];

  anchors = [];

  cur_index = -1;

  prev_index = -1;

  if (Array.prototype.indexOf) {
    App.$win.on("ready screenchange", function(ev) {
      var anchor, distances, offset, _i, _j, _len, _len1, _ref;
      if (ev.type === 'ready') {
        _ref = el.find("li a");
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          anchor = _ref[_i];
          el = $(anchor.getAttribute('href'));
          if (el) {
            spy_elements.push(el);
            anchors.push($(anchor));
          }
        }
      }
      distances = [];
      for (_j = 0, _len1 = spy_elements.length; _j < _len1; _j++) {
        el = spy_elements[_j];
        offset = el.offset();
        if (offset) {
          distances.push(Math.abs(offset.top - App.scrollY));
        }
      }
      cur_index = distances.indexOf(Math.min.apply(Math, distances));
      if (anchors[cur_index] && prev_index !== cur_index) {
        anchors[cur_index].addClass("in-view");
      }
      if (anchors[prev_index] && prev_index !== cur_index) {
        anchors[prev_index].removeClass("in-view");
      }
      return prev_index = cur_index;
    });
  }

}).call(this);

(function() {
  $(function() {
    return $('img[usemap]').rwdImageMaps();
  });

}).call(this);

(function() {
  $("a[target='share']").on("click", function(ev) {
    var height, left, options, top, url, width;
    url = $(this).attr("href");
    if (href.match(/(u|url)=$/)) {
      url = "" + url + (encodeURIComponent(window.location));
    }
    width = 600;
    height = 400;
    left = (window.screen.width - width) / 2;
    top = (window.screen.height - height) / 2;
    options = ["width=" + width, "height=" + height, "toolbar=no", "left=" + left, "top=" + top];
    window.open(url, 'share', options.join(","));
    return ev.preventDefault();
  });

}).call(this);

(function() {
  App.SlideShow = function(container) {
    var api;
    this.container = container;
    this.slides = [];
    this.list = null;
    new Hammer(this.container[0], {
      drag_block_horizontal: true
    }).on("swipeleft swiperight", function(ev) {
      if (ev.type === 'swiperight') {
        return api.prev();
      } else {
        return api.next();
      }
    });
    return api = {
      fullscreen: (function(_this) {
        return function() {
          var fn;
          if (Modernizr.prefixed("fullScreen", document) || Modernizr.prefixed("isFullScreen", document)) {
            fn = Modernizr.prefixed('cancelFullScreen', document);
          } else {
            fn = Modernizr.prefixed('requestFullScreen', _this.container[0]);
          }
          if (fn) {
            return fn();
          }
        };
      })(this),
      next: (function(_this) {
        return function() {
          var cur_index, to_index;
          cur_index = _this.list.filter(".active").index();
          if (_this.slides[cur_index + 1]) {
            to_index = cur_index + 1;
          } else {
            to_index = 0;
          }
          return api.show(to_index);
        };
      })(this),
      prev: (function(_this) {
        return function() {
          var cur_index, to_index;
          cur_index = _this.list.filter(".active").index();
          if (_this.slides[cur_index - 1]) {
            to_index = cur_index - 1;
          } else {
            to_index = _this.list.length - 1;
          }
          return api.show(to_index);
        };
      })(this),
      show: (function(_this) {
        return function(index) {
          if (index == null) {
            index = 0;
          }
          _this.list.removeClass("active");
          $(_this.list.get(index)).addClass("active");
          return YASS();
        };
      })(this),
      addSlides: (function(_this) {
        return function(images) {
          var alt, matches, src, srcset, _i, _len, _results;
          _results = [];
          for (_i = 0, _len = images.length; _i < _len; _i++) {
            src = images[_i];
            src = src.trim();
            if (src) {
              matches = src.match(/^(.+)(\((.+)\))$/);
              if (matches) {
                srcset = matches[1];
                alt = matches[3] || "";
              } else {
                srcset = src;
                alt = "";
              }
              _results.push(_this.slides.push({
                srcset: srcset,
                alt: alt
              }));
            } else {
              _results.push(void 0);
            }
          }
          return _results;
        };
      })(this),
      build: (function(_this) {
        return function() {
          var html, slide, ul, _i, _len, _ref;
          html = "<div class='slideshow'>\n  <nav>\n    <a class='prev' href='#'>Vorige</a>\n    <a class='next' href='#'>Volgende</a>\n    <a class='fullscreen' href='#'>Volledig scherm</a>\n  </nav>\n  <ul></ul>\n</div>";
          if (!_this.container.html().trim()) {
            _this.container.html(html);
            ul = _this.container.find("ul");
            _ref = _this.slides;
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
              slide = _ref[_i];
              ul.append("<li><img data-srcset='" + slide.srcset + "' alt='" + slide.alt + "'></li>");
            }
          }
          _this.list = _this.container.find("ul li");
          return _this.container.find("nav a").on("click", function(ev) {
            api[this.className]();
            return ev.preventDefault();
          });
        };
      })(this),
      destroy: (function(_this) {
        return function() {
          return _this.container.empty();
        };
      })(this)
    };
  };

}).call(this);

(function() {
  var recalc, stickies, sticky_elements, ticking, updateStickies;

  App.Sticky = function(el) {
    this.el = el;
    this.initial_pos = {
      top: 0,
      left: 0
    };
    this.initial_width = 0;
    this.parent = this.el.parent();
    return {
      update: (function(_this) {
        return function() {
          var should_stick;
          should_stick = _this.initial_pos.top - _this.initial_marginTop < App.scrollY;
          if (should_stick) {
            _this.el.addClass("is-sticky").css({
              width: _this.initial_width,
              left: _this.initial_pos.left
            });
            return _this.parent.addClass("contains-sticky");
          } else {
            _this.el.removeClass("is-sticky").removeAttr("style");
            return _this.parent.removeClass("contains-sticky");
          }
        };
      })(this),
      recalc: (function(_this) {
        return function() {
          _this.el.removeClass("is-sticky").removeAttr("style");
          _this.parent.removeClass("contains-sticky");
          _this.initial_pos = _this.el.offset();
          _this.initial_marginTop = parseInt(_this.el.css('margin-top'), 10);
          return _this.initial_width = _this.el.width();
        };
      })(this)
    };
  };

  sticky_elements = $(".sticky, .site-nav > .container, .site-nav .toggles, .site-pagenav");

  if (!Modernizr.positionfixed) {
    return;
  }

  ticking = false;

  recalc = true;

  stickies = [];

  updateStickies = function() {
    var sticky, _i, _len;
    for (_i = 0, _len = stickies.length; _i < _len; _i++) {
      sticky = stickies[_i];
      if (recalc) {
        sticky.recalc();
      }
      sticky.update();
    }
    recalc = false;
    return ticking = false;
  };

  sticky_elements.each(function() {
    var el;
    el = $(this);
    return stickies.push(new App.Sticky(el));
  });

  App.$win.on("load resizeend scrollend", function(ev) {
    if (ev.type !== 'scrollend') {
      recalc = true;
    }
    return updateStickies();
  });

}).call(this);

/**
 * Tabs
 * @example
 *  <a href="#tab1" class="tab-anchor-active">Tab 1</a>
 *  <a href="#tab2">Tab 2</a>
 *  <a href="#tab3">Tab 3</a>
 *
 *  <div id="tab1" data-tab-set="setname" class="tab-pane-active">Tab 1 contents</div>
 *  <div id="tab2" data-tab-set="setname">Tab 2 contents</div>
 *  <div id="tab3" data-tab-set="setname">Tab 3 contents</div>
 */

/**
 * find all anchors that link to a tab
 * @param {jQuery} tab
 * @returns {jQuery} $anchors
 */
function findTabAnchors(tab) {
    var tabId = $(tab).attr("id");
    return $("a").filter("[href=#"+ tabId +"]");
}

/**
 * find all tabs in set
 * @param {string} name
 * @return {jQuery} $tabs
 */
function findAllTabsInSet(name) {
    return $("[data-tab-set="+ name +"]");
}

/**
 * get the setname of a tab
 * @param {string} tab
 * @returns {string}
 */
function getTabSet(tab) {
    return $(tab).attr("data-tab-set");
}

/**
 * get the id of a tab
 * @param {string} tab
 * @returns {string}
 */
function getTabId(tab) {
    return $(tab).attr("id");
}

/**
 * show a tab
 * @param {jQuery} showTab
 * @return {boolean} shown
 */
function showTab(showTab) {
    var showTabId = getTabId(showTab);
    var tabSetName = getTabSet(showTab);
    var $allTabs = findAllTabsInSet(tabSetName);

    $allTabs.each(function() {
        var $tab = $(this);
        var show = (getTabId($tab) == showTabId);

        findTabAnchors($tab).toggleClass("tab-anchor-active", show);
        $tab.toggleClass("tab-pane-active", show).toggleClass("hide", !show);
    });

    return !!showTabId;
}

// auto find all anchors and do the magic
$(document.body).on("click", "a[href^=#]", function(ev) {
    var $target = $(this.getAttribute('href'));
    if(!$target.length || !$target.attr("data-tab-set")) {
        return;
    }

    if(showTab($target)) {
        ev.preventDefault();
        ev.stopImmediatePropagation();
        return false;
    }
});

(function() {
  var showTooltip;

  $(document.body).on("click", "a.tooltip", function(ev) {
    var anchor;
    anchor = $(this);
    ev.preventDefault();
    ev.stopPropagation();
    showTooltip(anchor);
    return $("a.tooltip.open").not(anchor).removeClass("open");
  }).on("click", function(ev) {
    return $("a.tooltip.open").removeClass("open");
  });

  showTooltip = function(el) {
    var body, className, h_out, offset, size, space, v_out;
    body = el.find(".tooltip-body");
    el.toggleClass("open");
    space = 20;
    offset = body.offset();
    size = {
      width: body.outerWidth(true) || 100,
      height: body.outerHeight(true) || 100
    };
    h_out = App.scrollX + App.win.width < (size.width + offset.left + space);
    v_out = App.scrollY + App.win.height < (size.height + offset.top + space);
    className = [v_out ? 'b' : 't', h_out ? 'r' : 'l'].join("");
    return body[0].className = "tooltip-body " + className;
  };

}).call(this);

(function() {
  $(function() {
    var city, form, routeInputs, titleMap, zipcode;
    zipcode = /^[1-9][0-9]{3}\s*[a-z]{2}$/i;
    city = /^[a-z\u00E0-\u00FC\-‘’'\/\(\) ]+$/i;
    form = $("#vananaarbeter-form");
    routeInputs = form.find("input[name=search_route_from], input[name=search_route_to]");
    titleMap = {
      search_route_from: 'Van',
      search_route_to: 'Naar'
    };
    return form.on("submit", function(ev) {
      var errors, focusField;
      errors = [];
      focusField = null;
      routeInputs.each(function() {
        var el, helpEl, val;
        el = $(this);
        helpEl = el.siblings(".help").hide();
        if (!helpEl.length) {
          helpEl = $("<span class='help'></span>").insertAfter(el).hide();
        }
        el.removeClass("error");
        val = this.value;
        if (!zipcode.test(val) && !city.test(val)) {
          focusField = this;
          helpEl.text("Vul een geldige postcode of plaatsnaam in.").show();
          return el.addClass("error");
        }
      });
      if (errors.length) {
        focusField.focus();
        return ev.preventDefault();
      }
    });
  });

}).call(this);


(function() {
  var handleXhrFormSubmit;

  handleXhrFormSubmit = function(ev) {
    var $form;
    ev.preventDefault();
    $form = $(this);
    return $.post($form.attr("action"), $form.serialize(), function(data) {
      return $form.replaceWith(data);
    });
  };

  $("body").on("submit", "form[target=xhr]", handleXhrFormSubmit);

}).call(this);
